package com.halflife.framework.participant;

import com.halflife.framework.participant.user.UserView;
import com.halflife.shiro.utils.ShiroUtil;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhaoyf on 2019/2/10.
 */
@Service
public class DepartmentService {
    @Resource
    private DepartmentRepository departmentRepository;
    public void initDepartment(HttpServletRequest request, Model model) {
        UserView user = ShiroUtil.getUserView(request);
        if (user == null || user.getId() == null) {
            throw new RuntimeException("请重新登陆");
        }
        Map departmentMap = new HashMap();
        departmentMap.put("id", user.getDepartmentId());
        List<Department> departments = departmentRepository.selectAll(departmentMap);
        model.addAttribute("departments", departments);
    }
}
